{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os, sys\n",
    "import time\n",
    "import datetime\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math\n",
    "from math import radians, cos, sin, asin, sqrt \n",
    "import random\n",
    "\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.ticker import MultipleLocator, FormatStrFormatter\n",
    "from matplotlib.patches import Ellipse, Circle\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# User defined Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''Time stamp'''\n",
    "def stamp_transit(time_str):\n",
    "    timeArray = time.strptime(time_str, \"%Y-%m-%d %H:%M:%S\")\n",
    "    timeStamp = int(time.mktime(timeArray))\n",
    "    return timeStamp\n",
    "    \n",
    "'''Time step'''\n",
    "\n",
    "def stamp_to_step(timestamp,date_str,step):\n",
    "    baseline = date_str+\" 00:00:00\";\n",
    "    baseline = int(stamp_transit(baseline))\n",
    "    current_step=int((timestamp-baseline)/step)\n",
    "    return current_step\n",
    "\n",
    "'''Grid Verifying'''\n",
    "\n",
    "def IntersectsSegment(ptx,pty,sptx,spty,eptx,epty): #0 for no, 1 for yes\n",
    "    #input: test point, start point , end point; all in format [lng, lat]\n",
    "    \n",
    "    if spty>pty and epty>pty: #segment over point\n",
    "        return 0\n",
    "    if spty<pty and epty<pty: #segment under point\n",
    "        return 0\n",
    "    if epty==pty: #end point is not counted\n",
    "        return 0\n",
    "    if sptx<ptx and eptx<ptx: #segment is on the left of test point\n",
    "        return 0\n",
    "    if spty==epty: #error\n",
    "        print('error')\n",
    "        return 0\n",
    "\n",
    "    xseg=eptx-(eptx-sptx)*(epty-pty)/(epty-spty) #lng of intersection\n",
    "    if xseg<ptx: #test point is on the right of segment\n",
    "        return 0\n",
    "    return 1  #test point intersects with segment\n",
    "\n",
    "def WithinHex(ptx,pty,hexg): # 0 for no, 1 for yes\n",
    "    #input test point and hexagon, all in format [lng, lat]\n",
    "    \n",
    "    if pty==hexg[2]:# test point is the lowest vertax\n",
    "        if ptx==hexg[1]:\n",
    "            return 1\n",
    "        else:\n",
    "            return 0\n",
    "        \n",
    "    if pty==hexg[8]:# test point is the highest vertax\n",
    "        if ptx==hexg[7]:\n",
    "            return 1\n",
    "        else:\n",
    "            return 0\n",
    "        \n",
    "    sc=0 # # of intersections\n",
    "    for i in range(0,5):\n",
    "        sc=sc+IntersectsSegment(ptx,pty,hexg[(2*i+1)],hexg[(2*i+2)],hexg[(2*i+3)],hexg[(2*i+4)])\n",
    "    \n",
    "    sc=sc+IntersectsSegment(ptx,pty,hexg[11],hexg[12],hexg[1],hexg[2])\n",
    "\n",
    "    if sc%2==1:# if the # of intersections is odd\n",
    "        return 1 # test point is in the hexagon\n",
    "    else:# if the # of intersections is even\n",
    "        return 0 # test point is not in the hexagon\n",
    "    \n",
    "def Get_grid(lng,lat,Grid_range):\n",
    "    for i in range(len(Grid_range)):\n",
    "        if WithinHex(lng,lat,Grid_range.iloc[i]):\n",
    "            return Grid_range.iloc[i,0]\n",
    "        else:\n",
    "            pass\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Spatial Range"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''Grid Range'''\n",
    "\n",
    "Grid_range=pd.read_csv('./Experiments/Demo/GridIndex.csv')\n",
    "\n",
    "Grid_range=Grid_range.drop(columns=['Unnamed: 0','Index'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Data processing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Driver_ID</th>\n",
       "      <th>Order_ID</th>\n",
       "      <th>Time_step</th>\n",
       "      <th>Grid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>8f20c9188561b796ef8e26196de30be4</td>\n",
       "      <td>39a096b71376b82f35732eff6d95779b</td>\n",
       "      <td>131</td>\n",
       "      <td>889386c312e02f8a</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>8f20c9188561b796ef8e26196de30be4</td>\n",
       "      <td>11746cc1d82418066fda69f08fb671c8</td>\n",
       "      <td>181</td>\n",
       "      <td>83fd0dce987f46ea</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>8f20c9188561b796ef8e26196de30be4</td>\n",
       "      <td>11746cc1d82418066fda69f08fb671c8</td>\n",
       "      <td>182</td>\n",
       "      <td>83fd0dce987f46ea</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           Driver_ID                          Order_ID  \\\n",
       "16  8f20c9188561b796ef8e26196de30be4  39a096b71376b82f35732eff6d95779b   \n",
       "88  8f20c9188561b796ef8e26196de30be4  11746cc1d82418066fda69f08fb671c8   \n",
       "99  8f20c9188561b796ef8e26196de30be4  11746cc1d82418066fda69f08fb671c8   \n",
       "\n",
       "    Time_step              Grid  \n",
       "16        131  889386c312e02f8a  \n",
       "88        181  83fd0dce987f46ea  \n",
       "99        182  83fd0dce987f46ea  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_str='2016-11-01'\n",
    "\n",
    "GPS_path='Dataset/gps_'+date_str.replace('-','')+'.csv'\n",
    "\n",
    "Order_path='Dataset//order_01-30/total_ride_request/order_'+date_str.replace('-','')+'.csv'\n",
    "\n",
    "Tracectory_data=pd.read_csv(GPS_path,header=None,\\\n",
    "                            names = ['Driver_ID','Order_ID','Time_Stamp','Longitude','Latitude'])\n",
    "\n",
    "Tracectory_data=Tracectory_data.iloc[:100]\n",
    "\n",
    "Tracectory_data['Time_step']=Tracectory_data.apply(lambda x:stamp_to_step(x['Time_Stamp'],date_str,300), axis=1)\n",
    "\n",
    "Tracectory_data=Tracectory_data.drop_duplicates(subset='Time_step', keep='last', inplace=False)\n",
    "\n",
    "Tracectory_data['Grid']=Tracectory_data.apply(lambda x:Get_grid(x['Longitude'],x['Latitude'],Grid_range), axis=1)\n",
    "\n",
    "Tracectory_data=Tracectory_data[['Driver_ID','Order_ID','Time_step','Grid']]\n",
    "\n",
    "Tracectory_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Order_ID</th>\n",
       "      <th>Start_step</th>\n",
       "      <th>Stop_step</th>\n",
       "      <th>Pickp_Grid</th>\n",
       "      <th>Dropoff_Grid</th>\n",
       "      <th>Reward_unit</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>eb9dd4095d9850e6287cefd813775a6c</td>\n",
       "      <td>117</td>\n",
       "      <td>123</td>\n",
       "      <td>9d2739e10948e232</td>\n",
       "      <td>541104d3641295d1</td>\n",
       "      <td>3.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>387a742fa5a3fbe4a1f215ac58ea33a8</td>\n",
       "      <td>186</td>\n",
       "      <td>193</td>\n",
       "      <td>e60c5c007507bcb0</td>\n",
       "      <td>7461298166b59abb</td>\n",
       "      <td>11.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9cf55f8e6e02a1e0f792df06e5d85011</td>\n",
       "      <td>251</td>\n",
       "      <td>255</td>\n",
       "      <td>390a600ae7dad222</td>\n",
       "      <td>f2de7e1d0d4f0637</td>\n",
       "      <td>5.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5feeae0307e15203484b9ffceef89855</td>\n",
       "      <td>200</td>\n",
       "      <td>204</td>\n",
       "      <td>1a58df7312309bd0</td>\n",
       "      <td>83fd0dce987f46ea</td>\n",
       "      <td>4.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ad4b52cb15b90c44c8f20a8b1e57a622</td>\n",
       "      <td>94</td>\n",
       "      <td>96</td>\n",
       "      <td>ccbdef31d728b7a0</td>\n",
       "      <td>310c5bac13100430</td>\n",
       "      <td>2.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ad551eb23b72e2a77ae5e81e22f2dbd0</td>\n",
       "      <td>226</td>\n",
       "      <td>230</td>\n",
       "      <td>9afea425734c0d96</td>\n",
       "      <td>e01ce17ed728a211</td>\n",
       "      <td>3.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ad4b52cb15b90c44c8f20a8b1e57a622</td>\n",
       "      <td>94</td>\n",
       "      <td>96</td>\n",
       "      <td>ccbdef31d728b7a0</td>\n",
       "      <td>310c5bac13100430</td>\n",
       "      <td>2.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>db46d8931c1ac3f61d8278df67c2a365</td>\n",
       "      <td>97</td>\n",
       "      <td>101</td>\n",
       "      <td>5bc416b12315fec4</td>\n",
       "      <td>f58efa07b5f95620</td>\n",
       "      <td>4.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>908e7f068da5768c492ab69dbf81efda</td>\n",
       "      <td>103</td>\n",
       "      <td>107</td>\n",
       "      <td>28129de1881e438e</td>\n",
       "      <td>6c02d478a91414bc</td>\n",
       "      <td>4.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2d48affae032a4ca29d220660732686d</td>\n",
       "      <td>108</td>\n",
       "      <td>113</td>\n",
       "      <td>6c02d478a91414bc</td>\n",
       "      <td>c8bcc56cd00c97c1</td>\n",
       "      <td>4.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>eb9dd4095d9850e6287cefd813775a6c</td>\n",
       "      <td>117</td>\n",
       "      <td>123</td>\n",
       "      <td>9d2739e10948e232</td>\n",
       "      <td>541104d3641295d1</td>\n",
       "      <td>3.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1cbbba13df0a8e2bb618809b94407329</td>\n",
       "      <td>223</td>\n",
       "      <td>226</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>9afea425734c0d96</td>\n",
       "      <td>2.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>ad551eb23b72e2a77ae5e81e22f2dbd0</td>\n",
       "      <td>226</td>\n",
       "      <td>230</td>\n",
       "      <td>9afea425734c0d96</td>\n",
       "      <td>e01ce17ed728a211</td>\n",
       "      <td>3.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>e48c52d65f29db1a612d9db3c1a29dc6</td>\n",
       "      <td>121</td>\n",
       "      <td>126</td>\n",
       "      <td>e7c52c7a8a41c2e0</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>5.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>b793e18edef3694f417552069d5c6fc8</td>\n",
       "      <td>127</td>\n",
       "      <td>131</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>f1eb6dbee4eda005</td>\n",
       "      <td>3.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>f8f9bc3d6753a9cc89256699b15d5fe9</td>\n",
       "      <td>44</td>\n",
       "      <td>47</td>\n",
       "      <td>677aa6c9a057914c</td>\n",
       "      <td>69339be3db147069</td>\n",
       "      <td>5.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>8e31f08bc942a63f53a46e149f354dfa</td>\n",
       "      <td>260</td>\n",
       "      <td>263</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>c25166539f059a37</td>\n",
       "      <td>2.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>d76426af74b69efc32c3c146a43f11c0</td>\n",
       "      <td>106</td>\n",
       "      <td>110</td>\n",
       "      <td>a0113f7277dc3ea1</td>\n",
       "      <td>2ed66b45dc347c3a</td>\n",
       "      <td>2.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>f78cfb7ef822ae67642d2952d94cdd77</td>\n",
       "      <td>113</td>\n",
       "      <td>118</td>\n",
       "      <td>7b2f5d75bac4ba28</td>\n",
       "      <td>31886db5b146394a</td>\n",
       "      <td>3.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>5c33acbf7ed4cddd9e3eadf73518661b</td>\n",
       "      <td>97</td>\n",
       "      <td>99</td>\n",
       "      <td>1537982892eeebad</td>\n",
       "      <td>7630c17cb951e013</td>\n",
       "      <td>2.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>7fdaadabbed8bc1370c2b6a40e3b6f29</td>\n",
       "      <td>100</td>\n",
       "      <td>103</td>\n",
       "      <td>2debe6ae3fa8ef6d</td>\n",
       "      <td>dd5aeea380406982</td>\n",
       "      <td>2.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>d76426af74b69efc32c3c146a43f11c0</td>\n",
       "      <td>106</td>\n",
       "      <td>110</td>\n",
       "      <td>a0113f7277dc3ea1</td>\n",
       "      <td>2ed66b45dc347c3a</td>\n",
       "      <td>2.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>04c2c45d01c4239c6471daf34ac34313</td>\n",
       "      <td>50</td>\n",
       "      <td>52</td>\n",
       "      <td>7630c17cb951e013</td>\n",
       "      <td>54f0dbb54c2a6cfb</td>\n",
       "      <td>1.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>815ba39849868f810421aa32e50a04d4</td>\n",
       "      <td>239</td>\n",
       "      <td>243</td>\n",
       "      <td>97243677f83bd758</td>\n",
       "      <td>df2cc10816de5ad6</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>ef8f64e5bc374dd6cf642a11068c4cdd</td>\n",
       "      <td>270</td>\n",
       "      <td>271</td>\n",
       "      <td>6a2e19aab9740e29</td>\n",
       "      <td>361516d75566d940</td>\n",
       "      <td>1.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>6e1ec81471248b9af71a0506032a5018</td>\n",
       "      <td>87</td>\n",
       "      <td>94</td>\n",
       "      <td>54f0dbb54c2a6cfb</td>\n",
       "      <td>8e1790041fe328d1</td>\n",
       "      <td>5.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>bda89887f6c1c8f2f7d1bf2364a9e823</td>\n",
       "      <td>90</td>\n",
       "      <td>93</td>\n",
       "      <td>310c5bac13100430</td>\n",
       "      <td>9ef8be81bdedcf31</td>\n",
       "      <td>3.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>cc9371c1b9e53a94054820d4720eb216</td>\n",
       "      <td>233</td>\n",
       "      <td>238</td>\n",
       "      <td>11506daa7b1c4cc6</td>\n",
       "      <td>97243677f83bd758</td>\n",
       "      <td>3.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>815ba39849868f810421aa32e50a04d4</td>\n",
       "      <td>239</td>\n",
       "      <td>243</td>\n",
       "      <td>97243677f83bd758</td>\n",
       "      <td>df2cc10816de5ad6</td>\n",
       "      <td>4.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>bfb529fd136838cfe557ace39b972e8a</td>\n",
       "      <td>103</td>\n",
       "      <td>108</td>\n",
       "      <td>0d3737cac500f237</td>\n",
       "      <td>2eadb9d8f64572ff</td>\n",
       "      <td>7.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>9c9299fcb09b32377d39ccba39d7378b</td>\n",
       "      <td>68</td>\n",
       "      <td>71</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>df2cc10816de5ad6</td>\n",
       "      <td>4.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>711b7cfeecb82804f80293f1c2151640</td>\n",
       "      <td>191</td>\n",
       "      <td>196</td>\n",
       "      <td>79b14d85f93977e4</td>\n",
       "      <td>8bb2c5ebcdb54493</td>\n",
       "      <td>3.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>8487dc784897db08a5b6eeb33b213acc</td>\n",
       "      <td>197</td>\n",
       "      <td>203</td>\n",
       "      <td>2ed66b45dc347c3a</td>\n",
       "      <td>bb5404544ea075dd</td>\n",
       "      <td>5.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>2f949ac8bb83e2acc3a2a3d038b844b7</td>\n",
       "      <td>155</td>\n",
       "      <td>158</td>\n",
       "      <td>e29bf8a357e9c86c</td>\n",
       "      <td>f2de7e1d0d4f0637</td>\n",
       "      <td>2.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>34bb59e7b9e851f14bee812aea63a85d</td>\n",
       "      <td>160</td>\n",
       "      <td>162</td>\n",
       "      <td>016937f21a2aa752</td>\n",
       "      <td>4ec7c2e2e2fcc0e3</td>\n",
       "      <td>1.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>9807a3a97678fed50912f1274b126657</td>\n",
       "      <td>163</td>\n",
       "      <td>164</td>\n",
       "      <td>379300c20ee553e4</td>\n",
       "      <td>0501af87f2ae3fa2</td>\n",
       "      <td>1.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>d323fd385d414d2d80eeb8e1407eb450</td>\n",
       "      <td>165</td>\n",
       "      <td>167</td>\n",
       "      <td>df9c5845db03c756</td>\n",
       "      <td>fa7248c2a1040346</td>\n",
       "      <td>2.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>9718cd846461660b909ca8a6723f864a</td>\n",
       "      <td>179</td>\n",
       "      <td>185</td>\n",
       "      <td>90e01b533621ea56</td>\n",
       "      <td>677aa6c9a057914c</td>\n",
       "      <td>7.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>55aaafa7672f336bd0bcb75ed7d458aa</td>\n",
       "      <td>168</td>\n",
       "      <td>171</td>\n",
       "      <td>fa7248c2a1040346</td>\n",
       "      <td>9ef8be81bdedcf31</td>\n",
       "      <td>3.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>889087e376b2b2d5d66b8a54c19a41ae</td>\n",
       "      <td>173</td>\n",
       "      <td>176</td>\n",
       "      <td>6a637710aca04528</td>\n",
       "      <td>90e01b533621ea56</td>\n",
       "      <td>2.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>4aad2a47a430b264c794aa652b035b29</td>\n",
       "      <td>98</td>\n",
       "      <td>102</td>\n",
       "      <td>016937f21a2aa752</td>\n",
       "      <td>541104d3641295d1</td>\n",
       "      <td>3.37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>66f318a72a4bead2382fb85e554fe30e</td>\n",
       "      <td>104</td>\n",
       "      <td>108</td>\n",
       "      <td>bc8495499e076192</td>\n",
       "      <td>bc6ccad91a69a805</td>\n",
       "      <td>3.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>be8096d4f21f8de67c289940179fcf24</td>\n",
       "      <td>250</td>\n",
       "      <td>253</td>\n",
       "      <td>7f6b780eea93b409</td>\n",
       "      <td>820535708cc56c72</td>\n",
       "      <td>1.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>8596d1f9499934afbfa9104ffa192f92</td>\n",
       "      <td>256</td>\n",
       "      <td>260</td>\n",
       "      <td>820535708cc56c72</td>\n",
       "      <td>e45b8f4573ae4b06</td>\n",
       "      <td>5.07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>7c2a70cf2a4b7bd276aa3acca641cf7f</td>\n",
       "      <td>261</td>\n",
       "      <td>263</td>\n",
       "      <td>0312d7104242036d</td>\n",
       "      <td>090d68df506b9670</td>\n",
       "      <td>1.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>da35fe6d3ce5297ec9ade6cbe1f15866</td>\n",
       "      <td>241</td>\n",
       "      <td>246</td>\n",
       "      <td>d0aeac1b273c68c0</td>\n",
       "      <td>9454535ceb37eba4</td>\n",
       "      <td>5.51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>aa43c726f753239cf678c07dad3f9e23</td>\n",
       "      <td>247</td>\n",
       "      <td>249</td>\n",
       "      <td>9454535ceb37eba4</td>\n",
       "      <td>016937f21a2aa752</td>\n",
       "      <td>1.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>be8096d4f21f8de67c289940179fcf24</td>\n",
       "      <td>250</td>\n",
       "      <td>253</td>\n",
       "      <td>7f6b780eea93b409</td>\n",
       "      <td>820535708cc56c72</td>\n",
       "      <td>1.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>7ff64cf7fecf747a2ea9d8f20142dca3</td>\n",
       "      <td>282</td>\n",
       "      <td>284</td>\n",
       "      <td>127d979915a239ac</td>\n",
       "      <td>f5d67d3a518321e5</td>\n",
       "      <td>3.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>427f25f5f574ffc076ef497928120e8c</td>\n",
       "      <td>230</td>\n",
       "      <td>231</td>\n",
       "      <td>c8bcc56cd00c97c1</td>\n",
       "      <td>e7c52c7a8a41c2e0</td>\n",
       "      <td>1.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>f976e70e496c2f9939da70b08771b4db</td>\n",
       "      <td>234</td>\n",
       "      <td>236</td>\n",
       "      <td>df433a35cb74b757</td>\n",
       "      <td>3b7be7b6774b122b</td>\n",
       "      <td>1.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>b27ef6e76fa049995ef7bd98e9c435c7</td>\n",
       "      <td>113</td>\n",
       "      <td>116</td>\n",
       "      <td>00543f55232a3ae3</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>2.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>a2aa3765bd47a8e7cc8aaac699bfa0cb</td>\n",
       "      <td>116</td>\n",
       "      <td>118</td>\n",
       "      <td>04417fb63aed6723</td>\n",
       "      <td>541104d3641295d1</td>\n",
       "      <td>1.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>105e2035bca8ae75c36fd1d20d57d329</td>\n",
       "      <td>215</td>\n",
       "      <td>221</td>\n",
       "      <td>df2cc10816de5ad6</td>\n",
       "      <td>9d2739e10948e232</td>\n",
       "      <td>5.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>b70785f5e34efbe358bacce501cf62c1</td>\n",
       "      <td>222</td>\n",
       "      <td>225</td>\n",
       "      <td>9d2739e10948e232</td>\n",
       "      <td>78aafeada01a51ab</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>e1c6d9b865c6723b69ed75f06ff7adbc</td>\n",
       "      <td>216</td>\n",
       "      <td>224</td>\n",
       "      <td>0c608c7fb57f7453</td>\n",
       "      <td>5ff970297f3ca58a</td>\n",
       "      <td>11.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>6135f2ffde4dc5cea7f1d9b119daee8b</td>\n",
       "      <td>237</td>\n",
       "      <td>243</td>\n",
       "      <td>674ca394ac845e91</td>\n",
       "      <td>bc8495499e076192</td>\n",
       "      <td>6.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>ba8d6472ed766d575d4a6aa91f1a02c5</td>\n",
       "      <td>245</td>\n",
       "      <td>249</td>\n",
       "      <td>7179ea6231b95e1a</td>\n",
       "      <td>8b626bd61f01a5ea</td>\n",
       "      <td>4.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>61d0b0a9aff7c4205250e606b7bb75a1</td>\n",
       "      <td>168</td>\n",
       "      <td>172</td>\n",
       "      <td>bc8495499e076192</td>\n",
       "      <td>6a2e19aab9740e29</td>\n",
       "      <td>3.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>b0e12c69aa7a24bbf7a048b41ec01ba8</td>\n",
       "      <td>172</td>\n",
       "      <td>178</td>\n",
       "      <td>6a2e19aab9740e29</td>\n",
       "      <td>bb5404544ea075dd</td>\n",
       "      <td>5.82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            Order_ID  Start_step  Stop_step        Pickp_Grid  \\\n",
       "0   eb9dd4095d9850e6287cefd813775a6c         117        123  9d2739e10948e232   \n",
       "1   387a742fa5a3fbe4a1f215ac58ea33a8         186        193  e60c5c007507bcb0   \n",
       "2   9cf55f8e6e02a1e0f792df06e5d85011         251        255  390a600ae7dad222   \n",
       "3   5feeae0307e15203484b9ffceef89855         200        204  1a58df7312309bd0   \n",
       "4   ad4b52cb15b90c44c8f20a8b1e57a622          94         96  ccbdef31d728b7a0   \n",
       "5   ad551eb23b72e2a77ae5e81e22f2dbd0         226        230  9afea425734c0d96   \n",
       "6   ad4b52cb15b90c44c8f20a8b1e57a622          94         96  ccbdef31d728b7a0   \n",
       "7   db46d8931c1ac3f61d8278df67c2a365          97        101  5bc416b12315fec4   \n",
       "8   908e7f068da5768c492ab69dbf81efda         103        107  28129de1881e438e   \n",
       "9   2d48affae032a4ca29d220660732686d         108        113  6c02d478a91414bc   \n",
       "10  eb9dd4095d9850e6287cefd813775a6c         117        123  9d2739e10948e232   \n",
       "11  1cbbba13df0a8e2bb618809b94407329         223        226  04417fb63aed6723   \n",
       "12  ad551eb23b72e2a77ae5e81e22f2dbd0         226        230  9afea425734c0d96   \n",
       "13  e48c52d65f29db1a612d9db3c1a29dc6         121        126  e7c52c7a8a41c2e0   \n",
       "14  b793e18edef3694f417552069d5c6fc8         127        131  04417fb63aed6723   \n",
       "15  f8f9bc3d6753a9cc89256699b15d5fe9          44         47  677aa6c9a057914c   \n",
       "16  8e31f08bc942a63f53a46e149f354dfa         260        263  04417fb63aed6723   \n",
       "17  d76426af74b69efc32c3c146a43f11c0         106        110  a0113f7277dc3ea1   \n",
       "18  f78cfb7ef822ae67642d2952d94cdd77         113        118  7b2f5d75bac4ba28   \n",
       "19  5c33acbf7ed4cddd9e3eadf73518661b          97         99  1537982892eeebad   \n",
       "20  7fdaadabbed8bc1370c2b6a40e3b6f29         100        103  2debe6ae3fa8ef6d   \n",
       "21  d76426af74b69efc32c3c146a43f11c0         106        110  a0113f7277dc3ea1   \n",
       "22  04c2c45d01c4239c6471daf34ac34313          50         52  7630c17cb951e013   \n",
       "23  815ba39849868f810421aa32e50a04d4         239        243  97243677f83bd758   \n",
       "24  ef8f64e5bc374dd6cf642a11068c4cdd         270        271  6a2e19aab9740e29   \n",
       "25  6e1ec81471248b9af71a0506032a5018          87         94  54f0dbb54c2a6cfb   \n",
       "26  bda89887f6c1c8f2f7d1bf2364a9e823          90         93  310c5bac13100430   \n",
       "27  cc9371c1b9e53a94054820d4720eb216         233        238  11506daa7b1c4cc6   \n",
       "28  815ba39849868f810421aa32e50a04d4         239        243  97243677f83bd758   \n",
       "29  bfb529fd136838cfe557ace39b972e8a         103        108  0d3737cac500f237   \n",
       "..                               ...         ...        ...               ...   \n",
       "70  9c9299fcb09b32377d39ccba39d7378b          68         71  04417fb63aed6723   \n",
       "71  711b7cfeecb82804f80293f1c2151640         191        196  79b14d85f93977e4   \n",
       "72  8487dc784897db08a5b6eeb33b213acc         197        203  2ed66b45dc347c3a   \n",
       "73  2f949ac8bb83e2acc3a2a3d038b844b7         155        158  e29bf8a357e9c86c   \n",
       "74  34bb59e7b9e851f14bee812aea63a85d         160        162  016937f21a2aa752   \n",
       "75  9807a3a97678fed50912f1274b126657         163        164  379300c20ee553e4   \n",
       "76  d323fd385d414d2d80eeb8e1407eb450         165        167  df9c5845db03c756   \n",
       "77  9718cd846461660b909ca8a6723f864a         179        185  90e01b533621ea56   \n",
       "78  55aaafa7672f336bd0bcb75ed7d458aa         168        171  fa7248c2a1040346   \n",
       "79  889087e376b2b2d5d66b8a54c19a41ae         173        176  6a637710aca04528   \n",
       "80  4aad2a47a430b264c794aa652b035b29          98        102  016937f21a2aa752   \n",
       "81  66f318a72a4bead2382fb85e554fe30e         104        108  bc8495499e076192   \n",
       "82  be8096d4f21f8de67c289940179fcf24         250        253  7f6b780eea93b409   \n",
       "83  8596d1f9499934afbfa9104ffa192f92         256        260  820535708cc56c72   \n",
       "84  7c2a70cf2a4b7bd276aa3acca641cf7f         261        263  0312d7104242036d   \n",
       "85  da35fe6d3ce5297ec9ade6cbe1f15866         241        246  d0aeac1b273c68c0   \n",
       "86  aa43c726f753239cf678c07dad3f9e23         247        249  9454535ceb37eba4   \n",
       "87  be8096d4f21f8de67c289940179fcf24         250        253  7f6b780eea93b409   \n",
       "88  7ff64cf7fecf747a2ea9d8f20142dca3         282        284  127d979915a239ac   \n",
       "89  427f25f5f574ffc076ef497928120e8c         230        231  c8bcc56cd00c97c1   \n",
       "90  f976e70e496c2f9939da70b08771b4db         234        236  df433a35cb74b757   \n",
       "91  b27ef6e76fa049995ef7bd98e9c435c7         113        116  00543f55232a3ae3   \n",
       "92  a2aa3765bd47a8e7cc8aaac699bfa0cb         116        118  04417fb63aed6723   \n",
       "93  105e2035bca8ae75c36fd1d20d57d329         215        221  df2cc10816de5ad6   \n",
       "94  b70785f5e34efbe358bacce501cf62c1         222        225  9d2739e10948e232   \n",
       "95  e1c6d9b865c6723b69ed75f06ff7adbc         216        224  0c608c7fb57f7453   \n",
       "96  6135f2ffde4dc5cea7f1d9b119daee8b         237        243  674ca394ac845e91   \n",
       "97  ba8d6472ed766d575d4a6aa91f1a02c5         245        249  7179ea6231b95e1a   \n",
       "98  61d0b0a9aff7c4205250e606b7bb75a1         168        172  bc8495499e076192   \n",
       "99  b0e12c69aa7a24bbf7a048b41ec01ba8         172        178  6a2e19aab9740e29   \n",
       "\n",
       "        Dropoff_Grid  Reward_unit  \n",
       "0   541104d3641295d1         3.54  \n",
       "1   7461298166b59abb        11.70  \n",
       "2   f2de7e1d0d4f0637         5.01  \n",
       "3   83fd0dce987f46ea         4.22  \n",
       "4   310c5bac13100430         2.27  \n",
       "5   e01ce17ed728a211         3.01  \n",
       "6   310c5bac13100430         2.27  \n",
       "7   f58efa07b5f95620         4.97  \n",
       "8   6c02d478a91414bc         4.90  \n",
       "9   c8bcc56cd00c97c1         4.61  \n",
       "10  541104d3641295d1         3.54  \n",
       "11  9afea425734c0d96         2.37  \n",
       "12  e01ce17ed728a211         3.01  \n",
       "13  04417fb63aed6723         5.07  \n",
       "14  f1eb6dbee4eda005         3.83  \n",
       "15  69339be3db147069         5.23  \n",
       "16  c25166539f059a37         2.34  \n",
       "17  2ed66b45dc347c3a         2.71  \n",
       "18  31886db5b146394a         3.01  \n",
       "19  7630c17cb951e013         2.13  \n",
       "20  dd5aeea380406982         2.45  \n",
       "21  2ed66b45dc347c3a         2.71  \n",
       "22  54f0dbb54c2a6cfb         1.79  \n",
       "23  df2cc10816de5ad6         4.40  \n",
       "24  361516d75566d940         1.82  \n",
       "25  8e1790041fe328d1         5.86  \n",
       "26  9ef8be81bdedcf31         3.22  \n",
       "27  97243677f83bd758         3.27  \n",
       "28  df2cc10816de5ad6         4.40  \n",
       "29  2eadb9d8f64572ff         7.55  \n",
       "..               ...          ...  \n",
       "70  df2cc10816de5ad6         4.45  \n",
       "71  8bb2c5ebcdb54493         3.79  \n",
       "72  bb5404544ea075dd         5.30  \n",
       "73  f2de7e1d0d4f0637         2.49  \n",
       "74  4ec7c2e2e2fcc0e3         1.92  \n",
       "75  0501af87f2ae3fa2         1.89  \n",
       "76  fa7248c2a1040346         2.33  \n",
       "77  677aa6c9a057914c         7.21  \n",
       "78  9ef8be81bdedcf31         3.04  \n",
       "79  90e01b533621ea56         2.14  \n",
       "80  541104d3641295d1         3.37  \n",
       "81  bc6ccad91a69a805         3.11  \n",
       "82  820535708cc56c72         1.84  \n",
       "83  e45b8f4573ae4b06         5.07  \n",
       "84  090d68df506b9670         1.99  \n",
       "85  9454535ceb37eba4         5.51  \n",
       "86  016937f21a2aa752         1.84  \n",
       "87  820535708cc56c72         1.84  \n",
       "88  f5d67d3a518321e5         3.28  \n",
       "89  e7c52c7a8a41c2e0         1.83  \n",
       "90  3b7be7b6774b122b         1.91  \n",
       "91  04417fb63aed6723         2.14  \n",
       "92  541104d3641295d1         1.81  \n",
       "93  9d2739e10948e232         5.78  \n",
       "94  78aafeada01a51ab         2.72  \n",
       "95  5ff970297f3ca58a        11.44  \n",
       "96  bc8495499e076192         6.99  \n",
       "97  8b626bd61f01a5ea         4.47  \n",
       "98  6a2e19aab9740e29         3.17  \n",
       "99  bb5404544ea075dd         5.82  \n",
       "\n",
       "[100 rows x 6 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Order_data=pd.read_csv(Order_path,header=None,\\\n",
    "                            names = ['Order_ID','Start_time','Stop_time','Pickup_Longitude','Pickup_Latitude',\\\n",
    "                                    'Dropoff_Longitude','Dropoff_Latitude','Reward_unit'])\n",
    "\n",
    "Order_data=Order_data.iloc[:100]\n",
    "\n",
    "Order_data['Start_step']=Order_data.apply(lambda x:stamp_to_step(x['Start_time'],date_str,300), axis=1)\n",
    "\n",
    "Order_data['Stop_step']=Order_data.apply(lambda x:stamp_to_step(x['Stop_time'],date_str,300), axis=1)\n",
    "\n",
    "Order_data['Pickp_Grid']=Order_data.apply(lambda x:Get_grid(x['Pickup_Longitude'],x['Pickup_Latitude'],Grid_range), axis=1)\n",
    "\n",
    "Order_data['Dropoff_Grid']=Order_data.apply(lambda x:Get_grid(x['Dropoff_Longitude'],x['Dropoff_Latitude'],Grid_range), axis=1)\n",
    "\n",
    "Order_data=Order_data[['Order_ID','Start_step','Stop_step','Pickp_Grid','Dropoff_Grid','Reward_unit']]\n",
    "\n",
    "Order_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
